#################################################################
#  Makefile for odrm server 
#  (c) 2015 deng guangyong (Beijing, China)
#  Writen by deng guangyong (xuanji00@gmail.com) - 2015-06-30
#################################################################

ROOT = .
BASE = .
MK_COMMON = .
BINNAME = odrmserver
LIBNAME = odrmserver

main_inc = $(ROOT)/src
main_src = $(ROOT)/src

srv_inc = $(ROOT)/src/libtcp
srv_src = $(ROOT)/src/libtcp

libev_inc = $(BASE)/libev/include
libev_lib = $(BASE)/libev/lib

obj_path = $(ROOT)/obj
dst_path = $(ROOT)/bin

bin = $(dst_path)/$(BINNAME)

#################################################################
#  Customization of the implicit rules

IFLAGS = -I$(sys_inc) -I$(main_inc) -I$(srv_inc) -I$(libev_inc) 
DEFS = -D_DEBUG 
SYSLIBS = -lrt -lm -lpthread -lev
APPLIBS = 
APPLFLAGS = -L$(libev_lib) 
CFLAGS = -Wall $(IFLAGS)

ifeq ($(MAKECMDGOALS), debug)
  CFLAGS = -g -Wall  $(IFLAGS) #$(DEFS)
  bin = $(dst_path)/$(BINNAME).dbg
endif

LIBS = $(APPLIBS) $(SYSLIBS)
LFLAGS = $(APPLFLAGS) $(SYSLFLAG)

#################################################################
#  Customization of the implicit rules - BRAIN DAMAGED makes (HP)

include $(MK_COMMON)/Makefile-linux.common


#################################################################
#  Modules

main_incs = $(wildcard $(main_inc)/*.h)
main_objs = $(obj_path)/aobjpool.o \
		$(obj_path)/inifile.o \
		$(obj_path)/main.o \
		$(obj_path)/rtsp.o \
		$(obj_path)/rtsphandler.o \

srv_incs = $(wildcard $(srv_inc)/*.h)
srv_objs = $(obj_path)/alog.o \
		$(obj_path)/tcpconn.o \
		$(obj_path)/tcpsrv.o \
		$(obj_path)/utils.o \

 
objs =  $(main_objs) $(srv_objs)  


#################################################################
#  Standard Rules

.PHONY: all clean debug 
 
all: clean $(bin)
debug: clean $(bin)

clean: 
	$(RM) $(objs)

$(bin): $(objs) 
	@(if [ ! -d ${obj} ]; then mkdir $(obj_path); fi)
	$(LINK) $@ $? $(LIBS)

#################################################################
#  Additional Rules

$(obj_path)/%.o: $(main_src)/%.c $(main_incs)
	$(COMPILE.c) $< -o $@		

$(obj_path)/%.o: $(srv_src)/%.c $(srv_incs)
	$(COMPILE.c) $< -o $@

$(obj_path)/%.o: $(srv_src)/%.cpp $(srv_incs)
	$(COMPILE.c) $< -o $@



